<template>
  <div class="model-comparison-container">
    <div class="models-row">
      <div class="model-column">
        <div class="model-header">
          <h3>RAGFlow</h3>
          <div v-if="modelComparisonResults.ragflow.loading" class="loading-indicator">
            <span>加载中...</span>
          </div>
        </div>
        <div class="model-content" v-html="formatMarkdown(modelComparisonResults.ragflow.result)"></div>
      </div>
      
      <div class="model-column">
        <div class="model-header">
          <h3>OpenAI</h3>
          <div v-if="modelComparisonResults.openai.loading" class="loading-indicator">
            <span>加载中...</span>
          </div>
        </div>
        <div class="model-content" v-html="formatMarkdown(modelComparisonResults.openai.result)"></div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import { marked } from 'marked';

export default {
  name: 'ModelComparisonView',
  computed: {
    ...mapState(['modelComparisonResults'])
  },
  methods: {
    formatMarkdown(text) {
      if (!text) return '';
      try {
        return marked(text);
      } catch (error) {
        console.error('解析Markdown出错:', error);
        return text;
      }
    }
  }
}
</script>

<style scoped>
.model-comparison-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.models-row {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.model-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 1px solid #e0e0e0;
  margin: 0 5px;
  border-radius: 5px;
  overflow: hidden;
  background-color: white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.model-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background-color: #f5f5f5;
  border-bottom: 1px solid #e0e0e0;
}

.model-header h3 {
  margin: 0;
  font-size: 16px;
  color: #333;
  font-weight: 500;
}

.model-content {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background-color: white;
  line-height: 1.6;
}

.loading-indicator {
  display: flex;
  align-items: center;
  font-size: 14px;
  color: #1890ff;
}

/* Deep selector to target markdown content */
:deep(h1), :deep(h2), :deep(h3), :deep(h4), :deep(h5), :deep(h6) {
  margin-top: 1em;
  margin-bottom: 0.5em;
  color: #333;
}

:deep(p) {
  margin-bottom: 1em;
  line-height: 1.6;
}

:deep(code) {
  background-color: #f5f5f5;
  padding: 2px 4px;
  border-radius: 3px;
  font-family: monospace;
}

:deep(pre) {
  background-color: #f5f5f5;
  padding: 12px;
  border-radius: 5px;
  overflow-x: auto;
  margin-bottom: 1em;
}

:deep(ul), :deep(ol) {
  padding-left: 20px;
  margin-bottom: 1em;
}

:deep(li) {
  margin-bottom: 0.5em;
}

:deep(a) {
  color: #1890ff;
  text-decoration: none;
}

:deep(a:hover) {
  text-decoration: underline;
}

:deep(blockquote) {
  border-left: 4px solid #1890ff;
  padding-left: 12px;
  color: #666;
  margin: 1em 0;
}

:deep(table) {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 1em;
}

:deep(th), :deep(td) {
  border: 1px solid #e0e0e0;
  padding: 8px 12px;
  text-align: left;
}

:deep(th) {
  background-color: #f5f5f5;
  font-weight: 500;
}

@media (max-width: 768px) {
  .models-row {
    flex-direction: column;
  }
  
  .model-column {
    margin: 5px 0;
  }
}
</style> 